﻿namespace ConsoleApp1
{
    using ExcelConfig.Config;
    using ExcelConfig.StoreAPI;
    using padmsg;

    internal class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8; 
            Console.WriteLine("Hello, World!");
            ConfigStoreHelper.EnterConfigStoreAPIConfig();

            var cfg = new AppConfigStreamFile(ConfigStoreAPI.Download("padmsg", "pad0001"));

            var api = new PadMsgAPI(cfg.Text("本地测试uri"), cfg.Text("AdminKey"));
            api.SetToken(cfg.Text("测试用Token"));
            if (!api.IsLogin())
            {
                byte[] qr = api.DownloadLoginQRcode();

                using (var f = File.Create(DateTime.UtcNow.Ticks + ".png"))
                {
                    f.Write(qr);
                    f.Flush();
                }
            }
            if (api.IsLogin())
            {
                using var ws = PadMsgAPI.ListenMsg(cfg.Text("测试收消息ws"), cfg.Text("测试用Token"), PadMsgAPI.on_message);
                lock (ws) while (ws.IsConnected) Monitor.Wait(ws, 1000);
            }
        }
    }
}
